<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>组件 v-model</title>
</head>
<body>

    <div id="app">
            <input
            v-bind:value="searchText"
            v-on:input="searchText = $event.target.value"
          >
          <label for="">{{searchText}}</label>
       
        <!-- <custom-input :value="searchText" @input="searchText = $event"></custom-input> -->
        <!-- v-model效果同上 -->
        <custom-input v-model="searchText"></custom-input>
        
    </div>    

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>
    <script>

        Vue.component('custom-input',{
            props:['value'],
            template:
            `
                <input
                    v-bind:value="value"
                    v-on:input = "$emit('input',$event.target.value)"
                    
                >
            `
        })

        var app = new Vue({
            el:"#app",
            data:{
                searchText:''
            }
        })
    </script>
</body>
</html>